package net.xdclass.execption;

import lombok.extern.slf4j.Slf4j;
import net.xdclass.util.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @Author: fengh
 * @Date: 2023/6/14 18:54
 */
@ControllerAdvice
@Slf4j
//@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public JsonData handle(Exception e){
        if (e instanceof BizException) {
            BizException bizException = (BizException) e;
            log.error("[业务异常]",e);
            return JsonData.buildError(bizException.getMsg());
        }else {
            log.info("系统异常",e);
            return JsonData.buildError("全局异常,未知错误");
        }
    }

}
